package logic

import (
	"context"
	"warehouse/mysql"

	"warehouse/warerpc/internal/svc"
	"warehouse/warerpc/warerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WareAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWareAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WareAddLogic {
	return &WareAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *WareAddLogic) WareAdd(in *warerpc.WareAddRequest) (*warerpc.WareAddResponse, error) {
	// todo: add your logic here and delete this line

	ware := mysql.Ware{
		Name:    in.Name,
		Address: in.Address,
	}
	mysql.DB.Debug().Create(&ware)

	return &warerpc.WareAddResponse{
		WareId: int64(ware.ID),
	}, nil
}
